//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"

//SAGITTARIUS headers:
#include "sagittarius/mem/sizeclass.h"

int n_sizeclasses() { return 58; }

sg_sclass get_ksc(size_t bytes) {
    AT(bytes > 0);
    if(bytes <= 64)
        if(bytes <= 4)
            return bytes;
        else //>4
            if(bytes <= 16)
                return ((bytes-5)>>1) + 5;
            else //>16
                return ((bytes-17)>>2) + 11;
    else // > 64
        if(bytes <= 1024)
            if(bytes <= 256)
                return ((bytes-65)>>4) + 23;
            else //>256
                return ((bytes-257)>>6) + 35;
        else //> 1024
            return ((bytes-1025)>>8) + 47;
}

size_t sg_sc_nbytes(sg_sclass sc) {
    switch(sc) {
        //case 0:
            //return 0;
        case 1:
            return 1;
        case 2:
            return 2;
        case 3:
            return 3;
        case 4:
            return 4;
        case 5:
            return 6;
        case 6:
            return 8;
        case 7:
            return 10;
        case 8:
            return 12;
        case 9:
            return 14;
        case 10:
            return 16;
        case 11:
            return 20;
        case 12:
            return 24;
        case 13:
            return 28;
        case 14:
            return 32;
        case 15:
            return 36;
        case 16:
            return 40;
        case 17:
            return 44;
        case 18:
            return 48;
        case 19:
            return 52;
        case 20:
            return 56;
        case 21:
            return 60;
        case 22:
            return 64;
        case 23:
            return 80;
        case 24:
            return 96;
        case 25:
            return 112;
        case 26:
            return 128;
        case 27:
            return 144;
        case 28:
            return 160;
        case 29:
            return 176;
        case 30:
            return 192;
        case 31:
            return 208;
        case 32:
            return 224;
        case 33:
            return 240;
        case 34:
            return 256;
        case 35:
            return 320;
        case 36:
            return 384;
        case 37:
            return 448;
        case 38:
            return 512;
        case 39:
            return 576;
        case 40:
            return 640;
        case 41:
            return 704;
        case 42:
            return 768;
        case 43:
            return 832;
        case 44:
            return 896;
        case 45:
            return 960;
        case 46:
            return 1024;
        case 47:
            return 1280;
        case 48:
            return 1536;
        case 49:
            return 1792;
        case 50:
            return 2048;
        case 51:
            return 2304;
        case 52:
            return 2560;
        case 53:
            return 2816;
        case 54:
            return 3072;
        case 55:
            return 3328;
        case 56:
            return 3584;
        case 57:
            return 3840;
        case 58:
            return 4096;
        default:
            AN(0);
    }
}